package cool.webstudy.admin.constant.enums.rescode.docker;

import cool.webstudy.admin.constant.enums.rescode.BaseResCodeEnum;
import lombok.extern.slf4j.Slf4j;

/**
 * @author 莫振双
 * @date 2025/1/1 21:05
 * @description: 容器相关错误码
 */
@Slf4j
public enum ContainerResCodeEnum implements BaseResCodeEnum {
    RC_START_PORT_NUM_NOT_LESS_THAN_END_PORT_NUM("80001", "截止端口号不能小于起始端口号"),
    RC_ERROR_CREATE("80002", "创建容器失败，失败详情：{0}"),
    RC_ERROR_IP_LIST_IS_EMPTY("80003", "创建容器失败，无法生成ip地址！"),
    RC_ERROR_DELETE("80004", "删除容器失败，失败详情：{0}"),
    RC_ERROR_STOP("80005", "停止容器失败，失败详情：{0}"),
    ;
    private String code;
    private String msg;

    ContainerResCodeEnum(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    @Override
    public String code() {
        return code;
    }

    @Override
    public String msg() {
        return msg;
    }

    /**
     * 根据code获取msg静态方法，每个响应状态码枚举类都应有这个方法
     */
    public static ContainerResCodeEnum getMsgByCode(String code) {
        for (ContainerResCodeEnum containerResCodeEnum : ContainerResCodeEnum.values()) {
            if (containerResCodeEnum.code().equals(code)) {
                return containerResCodeEnum;
            }
        }
        log.error("getMsgByCode error:无法获取枚举值");
        return null;
    }
}
